﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using System.Windows.Navigation;

namespace Wintellect.Touch.Views
{
    public partial class ChildWindowPage : Page
    {
        public ChildWindowPage()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void HandleShowChildWindowClick(Object sender, RoutedEventArgs e)
        {
            ShowChildWindow();
        }

        private void HandleShowPopup(Object sender, RoutedEventArgs e)
        {
            var popup = new Popup {VerticalOffset = 200, HorizontalOffset = 200};

            var childWindowButton = new Button
                                        {
                                            Content = "Show Child Window", 
                                            Padding = new Thickness(30.0),
                                            HorizontalAlignment = HorizontalAlignment.Center,
                                            VerticalAlignment = VerticalAlignment.Center,
                                        };
            childWindowButton.Click += (o, args) => ShowChildWindow();

            
            var closePopupButton = new Button
                                       {
                                           Content="Close Popup",
                                           Padding=new Thickness(30.0),
                                           HorizontalAlignment = HorizontalAlignment.Center,
                                           VerticalAlignment = VerticalAlignment.Center,
                                       };
            closePopupButton.Click += (o, args) => popup.IsOpen = false;

            var stackPanel = new StackPanel
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Center,
                Width = 300,
                Height = 300,
            };

            stackPanel.Children.Add(childWindowButton);
            stackPanel.Children.Add(closePopupButton);

            var border = new Border
                             {
                                 BorderThickness = new Thickness(1),
                                 BorderBrush = new SolidColorBrush(Colors.Black),
                                 Background = new SolidColorBrush(Colors.LightGray),
                                 Child = stackPanel
                             };

            popup.Child = border;
            popup.IsOpen = true;
        }

        private void HandleShowNestedChild(Object sender, RoutedEventArgs e)
        {
            var childWindowButton = new Button
                                        {
                                            Content = "Show Child Window",
                                            Padding = new Thickness(30.0),
                                            HorizontalAlignment = HorizontalAlignment.Center,
                                            VerticalAlignment = VerticalAlignment.Center,
                                        };
            childWindowButton.Click += (o, args) => ShowChildWindow();

            var border = new Border
                             {
                                 BorderThickness = new Thickness(1),
                                 BorderBrush = new SolidColorBrush(Colors.Black),
                                 Background = new SolidColorBrush(Colors.LightGray),
                                 Child = childWindowButton
                             };

            var grid = new Grid
                           {
                               HorizontalAlignment = HorizontalAlignment.Stretch,
                               VerticalAlignment = VerticalAlignment.Stretch,
                               Width=300,
                               Height=300,
                           };
            grid.Children.Add(border);

            var childWindow = new ChildWindow
                                  {
                                      Content = grid
                                  };
            childWindow.Show();
        }

        private void ShowChildWindow()
        {
            var childWindow = new TouchChildWindow();
            childWindow.Show();
        }
    }
}
